﻿using System.Collections;
using System.Collections.Generic;

namespace Library.OrmEnterpriseEntity.TableInfo {
  public class LinkListCollection<T> : ICollection<T> where T : DbTable, new() {
    public LinkListCollection() {
      _list = new LinkedList<T>();
    }
    private readonly LinkedList<T> _list;
    #region Implementation of IEnumerable

    public IEnumerator<T> GetEnumerator() {
      return _list.GetEnumerator();
    }

    IEnumerator IEnumerable.GetEnumerator() {
      return GetEnumerator();
    }

    #endregion

    #region Implementation of ICollection<T>

    public void Add(T item) {
      _list.AddLast(item);
    }

    public void Clear() {
      _list.Clear();
    }

    public bool Contains(T item) {
      return _list.Contains(item);
    }

    public void CopyTo(T[] array, int arrayIndex) {
      _list.CopyTo(array, arrayIndex);
    }

    public bool Remove(T item) {
      return _list.Remove(item);
    }

    public int Count {
      get { return _list.Count; }
    }

    public bool IsReadOnly {
      get { return false; }
    }

    #endregion
  }
}
